import { Channel } from '@/types/data'
import { HomeAction } from '@/types/store'
type StateType = {
  channels: Channel[]
  allChannels: Channel[]
  active: number
}
const initState: StateType = {
  channels: [],
  allChannels: [],
  active: 0,
}
const home = (state = initState, action: HomeAction) => {
  if (action.type === 'home/saveChannels') {
    return {
      ...state,
      channels: action.payload,
    }
  }

  if (action.type === 'home/saveAllChannels') {
    return {
      ...state,
      allChannels: action.payload,
    }
  }

  if (action.type === 'home/setChannelActive') {
    return {
      ...state,
      active: action.payload,
    }
  }
  return state
}

export default home
